package event;

/**
 *  面向对象风格
 */

public class ObjectOriented {
    public String process() {
        KWIC kwic = new KWIC();
        return kwic.generateKwic();
    }

    class KWIC {
        private String[] lines = {
            "Liu Jin Qi is learning",
            "Software architecture is essential",
            "Understanding design patterns is crucial"
        };

        public String generateKwic() {
            StringBuilder result = new StringBuilder();
            for (String line : lines) {
                result.append(kwicShift(line)).append("\n");
            }
            return result.toString();
        }

        private String kwicShift(String line) {
            String[] words = line.split(" ");
            StringBuilder shifted = new StringBuilder();
            for (int i = 0; i < words.length; i++) {
                for (int j = i; j < words.length; j++) {
                    shifted.append(words[j]).append(" ");
                }
                for (int k = 0; k < i; k++) {
                    shifted.append(words[k]).append(" ");
                }
                shifted.append("\n");
            }
            return shifted.toString();
        }
    }
}
